fix: text length code cleanup - #135
Merged
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This pull request standardizes text access and length calculations across the Android editor implementation by preferring length() and editableText over direct text?.length / text usage, improving consistency when working with editable buffers and spans.
Changes:
- Replaced several
text?.length ?: 0usages withlength()for consistent bounds clamping. - Switched span-related operations from
texttoeditableTextto ensure operations apply to the editable spannable buffer.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| android/src/main/java/com/swmansion/enriched/utils/EnrichedSelection.kt | Uses view.length() for selection clamping instead of text?.length. |
| android/src/main/java/com/swmansion/enriched/EnrichedTextInputView.kt | Updates selection clamping and span redraw logic to use length() / editableText. |
| android/src/main/java/com/swmansion/enriched/EnrichedDragHandler.kt | Uses view.length() for pre-drop text length capture. |
| android/src/main/java/com/swmansion/enriched/CheckListClickHandler.kt | Uses editableText as the spannable source for checklist span hit-testing and toggling. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This pull request refactors several classes to consistently use the
length()andeditableTextAPIs instead of directly accessing thetextproperty or its length. This improves reliability and clarity, especially when dealing with editable text fields and their spans.Consistent text length and access handling:
text?.lengthwithlength()inEnrichedDragHandler,EnrichedTextInputView, andEnrichedSelectionto ensure accurate and null-safe text length retrieval.texttoeditableTextwhen accessing or modifying the text content inCheckListClickHandlerandEnrichedTextInputView, ensuring that operations are performed on the editable buffer.These changes enhance code safety and maintainability by standardizing how text content is accessed and manipulated across the codebase.
Test Plan
Provide clear steps so another contributor can reproduce the behavior or verify the feature works.
For example:
Screenshots / Videos
Include any visual proof that helps reviewers understand the change — UI updates, bug reproduction or the result of the fix.
Compatibility